package cn.sh.tools.annotation;

import cn.sh.tools.domain.constant.WeChatConstant;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author shihao
 * @description 企业微信debug切面，在原有请求的URI加上【&debug=1】
 */
@Aspect
@Component
@Slf4j
public class WeChatAspect {

    @Pointcut("@annotation(cn.sh.tools.annotation.WeChat)")
    public void weChat() {
    }

    @AfterReturning(value = "weChat()", returning = "URI")
    public String after(JoinPoint joinPoint, String URI) {
        String lastParam = "debug=1";
        if (URI.contains(WeChatConstant.QUESTION_MARK)) {
            return URI + WeChatConstant.EQUAL_SIGN + lastParam;
        }
        return URI + WeChatConstant.QUESTION_MARK + lastParam;
    }

}
